<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<title>首页</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="keywords" content="" />

<!-- easyui -->
<script type="text/javascript" th:src="@{/easyui/jquery.min.js}" ></script>
<script type="text/javascript" th:src="@{/easyui/jquery.easyui.min.js}"></script>
<link rel="stylesheet" type="text/css" th:href="@{/easyui/themes/default/easyui.css}">
<link rel="stylesheet" type="text/css" th:href="@{/easyui/themes/icon.css}">
<link rel="stylesheet" type="text/css" th:href="@{/easyui/themes/color.css}">
	<script type="text/javascript" th:src="@{/easyui/locale/easyui-lang-zh_CN.js}"></script>
	<style>
		#list{
			padding: 5px;
		}
		#moreForm,#editForm{
			padding: 15px;
		}
		#moreForm>*,#editForm>*{
			margin-top: 10px;
		}
	</style>
</head>
<body>
<!-- 工具条 -->
	<div id="tool_bar">
		<a id="moreBtn" href="#" class="easyui-linkbutton">查看更多</a>
		<a id="applyBtn" href="#" class="easyui-linkbutton">实验申请</a>
		<a id="addBtn" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add'">添加</a>
		<a id="editBtn" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-edit'">修改</a>
		<a id="deleteBtn" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-remove'">删除</a>
		<a id="importBtn" href="#" class="easyui-linkbutton" >导入</a>
		<a id="exportBtn" href="#" class="easyui-linkbutton" >导出</a>
	</div>
	<div th:replace="commons/pub::#tool_bar"></div>
	<!-- 编辑窗口 -->
	<div id="win">
		<form id="editForm" method="post" >
			编号：<input name="id" type="number" class="easyui-validatebox" data-options="required:true"/><br>
			申请人id：<input name="apply_id" class="easyui-validatebox" data-options="required:true"/><br>
			项目名称：<input name="project_name" class="easyui-validatebox" data-options="required:true"/><br>
			所属院系：<input name="college" class="easyui-validatebox"/><br>
			项目类型:<input name="type" class="easyui-validatebox" /><br>
			项目描述:<input name="describe" class="easyui-validatebox"/><br>
			开始日期:<input name="start_date" class="easyui-validatebox"/><br>
			结束日期:<input name="end_date" class="easyui-validatebox"/><br>
			状态:<input name="state" type="radio" class="easyui-validatebox" value="0"/>未批准
			<input name="state" type="radio" class="easyui-validatebox" value="1"/>通过
			<input name="state" type="radio" class="easyui-validatebox" value="2"/>审核中
			<input name="state" type="radio" class="easyui-validatebox" value="3"/>实验结束<br>
			<a id="saveBtn" href="#" class="easyui-linkbutton">保存</a>
		</form>
	</div>
	<div id="more">
		<form id="moreForm" method="post" >
			编号：<input name="apply_id" disabled="disabled" class="easyui-validatebox" /><br>
			申请人id：<input name="apply_id" disabled="disabled" class="easyui-validatebox"/><br>
			项目名称：<input name="project_name" disabled="disabled" class="easyui-validatebox" /><br>
			所属院系：<input name="college" disabled="disabled" class="easyui-validatebox"/><br>
			项目类型:<input name="type" disabled="disabled" class="easyui-validatebox" /><br>
			项目描述:<input name="describe" disabled="disabled" class="easyui-validatebox"/><br>
			开始日期:<input name="start_date" disabled="disabled" class="easyui-validatebox"/><br>
			结束日期:<input name="end_date" disabled="disabled" class="easyui-validatebox"/><br>
			状态:状态:<input name="state" type="radio" class="easyui-validatebox" value="0"/>未批准
			<input name="state" type="radio" class="easyui-validatebox" value="1"/>通过
			<input name="state" type="radio" class="easyui-validatebox" value="2"/>审核中
			<input name="state" type="radio" class="easyui-validatebox" value="3"/>实验结束<br><br>
		</form>
	</div>
	<script type="text/javascript" th:inline="none">
	$(document).ready(function (){
		$('#list').datagrid({   
		    url:'/project/listByPage',
		    columns:[[   
		        {field:'num',checkbox:true},
		        {field:'id',title:'编号',width:'20%',align:'center'},
		        {field:'apply_id',title:'申请人id',width:'20%',align:'center'},
		        {field:'project_name',title:'项目名称',width:'20%',align:'center'},
		        {field:'college',title:'所属院系',width:'20%',align:'center'},
				{field:'state',title:'状态',width:'15%',align:'center'}
		    ]],
		    pagination:true,
		    toolbar:"#tool_bar"
		});
		$("#moreBtn").click(function (){
			//判断只能选择一行
			var rows=$("#list").datagrid('getSelections');
			if(rows.length!=1){
				$.messager.alert("提示","查看操作只能选择一行","warning");
				return;
			}
			//表单回显
			$("#moreForm").form("load","/project/findProjectById?id="+rows[0].id+"");
			$("#more").window("open");
		});

		$('#win').window({
		    width:600,   
		    height:400, 
		    padding:30,
		    closed:true,
		    title:"用户编辑",
		    modal:true  
		});
		$('#more').window({
			width:600,
			height:400,
			padding:30,
			closed:true,
			title:"用户编辑",
			modal:true
		});
		/*增加用户*/
		$("#addBtn").click(function(){
			$("#editForm").form("clear");
			$("#win").window("open");
		});
		/*保存*/
		$("#saveBtn").click(function () {
			$("#editForm").form("submit",{
				url:"/project/saveProject",     //提交表单
				onSubmit:function(){
					return $("#editForm").form("validate");
				},
				success:function(data){   //回传数据
					data=eval("("+data+")")
					if(data.success){
						$("#win").window("close");
						$("#list").datagrid("reload");
						$.messager.alert("提示","保存成功!","info");
					}else{
						$.messager.alert("提示","保存失败!",data.msg,"error");
					}
				}
			});
		})
		//修改数据
		$("#editBtn").click(function(){
			//判断只能选择一行
			var rows=$("#list").datagrid("getSelections");
			if(rows.length!=1){
				$.messager.alert("提示","修改操作只能选择一行","warning");
				return;
			}
			//表单回显
			$("#editForm").form("load","/project/findProjectById?id="+rows[0].id+"");
			$("#win").window("open");
		});
		//删除功能
		$("#deleteBtn").click(function(){
			//判断只能选择一行
			var rows=$("#list").datagrid("getSelections");
			if(rows.length==0){
				$.messager.alert("提示","删除操作至少选择一行","warning");
				return;
			}
			$.messager.confirm("提示","确定删除吗？",function(value){
				if(value){
					//执行删除,遍历数据
					var idStr= "";
					$(rows).each(function(i){
						idStr+=("id="+rows[i].id);
						if(i!=$(rows).length-1){
							idStr+="&";
						}
					});
					$.post("/project/delectProject",idStr,function(data){
						if(data.success){
							$("#list").datagrid("reload");
							$.messager.alert("提示","删除成功!","info");
						}else{
							$.messager.alert("提示","删除失败!",data.msg,"error");
						}
					},"json");
				}
			});
		});
	});
	</script>

</body>